const app =getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    name:"",
    lawyer_info:{},
    current_page:1,
    last_page:1,
    lawyerId:'',
    text:"距离",
    domainName:"领域名称",
    value1: 0,
    value2: "b",
    option2: [
      { text: "好评排序", value: "好评排序" },
      { text: "销量排序", value: "销量排序" }
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({lawyerId:options.lawyerId})
    this.getData()
  },
  change({detail }){
    this.setData({
      text:detail 
    })
  },
  domain(e){
    this.selectComponent("#domain").toggle();
    this.setData({
      domainName:e.currentTarget.dataset.name
    })
  },
  getData(searchName=""){
    let urlStr =app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.lawyer-firm.getLawyerList");
    app._postNetWork({
      url: urlStr,
      data:{
        id:this.data.lawyerId,
        name:searchName
      },
      success: (res) => {
        console.log(res)
        if (res.data.result == 1) {
            this.setData({
              lawyer_info: res.data.data.list,
              current_page:res.data.data.list.current_page,
              last_page:res.data.data.list.last_page
            })
        } else {
          app.tips(res.data.msg)
        }
      }
    })
  },
  onCancel(){
    this.setData({name:''})
  },
   onChange(e) {
    this.setData({
      name: e.detail,
    });
    if(this.data.timerId){
      clearTimeout(this.data.timerId)
    }
    this.data.timerId = setTimeout(() => {
      this.getData(e.detail)
    }, 350);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.current_page>=this.data.last_page){
      let urlStr =app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.lawyer-firm.getLawyerList");
      app._postNetWork({
        url: urlStr,
        data:{
          id:this.data.lawyerId,
          name:searchName
        },
        success: (res) => {
          if (res.data.result == 1) {
            this.data.lawyer_info.data.concat(res.data.data.list.data);
              this.setData({
                lawyer_info: this.data.lawyer_info,
                current_page:res.data.list.current_page,
                last_page:res.data.list.last_page
              })
          } else {
            app.tips(res.data.msg)
          }
        }
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let id=wx.getStorageSync('uid');
    return {
      title:"邀请律师",
      path:"/packageI/lawyerPlatform/info/info?type=lawyerdetail&share=lawyer&merchant_member_id="+id
    }
  }
})